package com.yfbao.horizon.utils;

import java.util.UUID;
import java.util.function.Supplier;

public class ComUtils {

    public static Long uuidLong() {
        return UUID.randomUUID().getMostSignificantBits();
    }

    public static long uuidAbsLong() {
        long r = uuidLong();
        if (r < 0L) {
            r &= 9223372036854775807L;
        }

        return r;
    }

    public static String uuidString() {
        return uuidLong().toString();
    }


    /**
     * 封装：执行租户下执行一段逻辑
     * @param tenantId
     * @param supplier
     * @param <T>
     * @return
     */
    public static <T> T tenantOperation(Long tenantId, Supplier<T> supplier){
        try{
            System.out.println("begin.......");
            return supplier.get();
        }finally {
            System.out.println("finaly.......");
        }
    }

    public static <T> void tenantOperation2(Long tenantId, Supplier<T> supplier){
        try{
            System.out.println("begin.......");
        }finally {
            System.out.println("finaly.......");
        }
    }
}
